﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dapper.Repository.Base
{
    public interface IRepository<T,T1> where T : BaseEntity<T1>
    {
        /// <summary>
        /// Get entity by identifier
        /// </summary>
        /// <param name="id">Identifier</param>
        /// <returns>Entity</returns>
        T GetById(T1 id, IDbConnection con, IDbTransaction transaction = null, string returnFields = null);

        /// <summary>
        /// Insert entity
        /// </summary>
        /// <param name="entity">Entity</param>
        void Insert(T entity, IDbConnection con, IDbTransaction transaction = null);

        /// <summary>
        /// Insert entities
        /// </summary>
        /// <param name="entities">Entities</param>
        void Insert(IEnumerable<T> entities, IDbConnection con, IDbTransaction transaction = null);

        /// <summary>
        /// Update entity
        /// </summary>
        /// <param name="entity">Entity</param>
        void Update(T entity, IDbConnection con, IDbTransaction transaction = null, string updateFields = null);

        /// <summary>
        /// Update entities
        /// </summary>
        /// <param name="entities">Entities</param>
        void Update(IEnumerable<T> entities, IDbConnection con, IDbTransaction transaction = null);

        /// <summary>
        /// Delete entity
        /// </summary>
        /// <param name="entity">Entity</param>
        void Delete(T entity, IDbConnection con, IDbTransaction transaction = null);

        /// <summary>
        /// Delete entities
        /// </summary>
        /// <param name="entities">Entities</param>
        void Delete(IEnumerable<T> entities, IDbConnection con, IDbTransaction transaction = null);

        /// <summary>
        /// 分页查询单表数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        IEnumerable<T> GetByPageIndex(int pageIndex, int pageSize, IDbConnection con, IDbTransaction transaction = null, string returnFields = null, string where = null, object param = null, string orderBy = null);


        /// <summary>
        /// 根据sql语句获取表格
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        DataTable GetDataTable(string sql, IDbConnection con, IDbTransaction transaction = null, object param = null);


        /// <summary>
        /// 返回自定类型DTO
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        IEnumerable<T2> GetDynimic<T2>(string sql, IDbConnection con, IDbTransaction transaction = null, object param = null);
       
    }
}
